package com.zimi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zimi.model.SysOrgExtend;
import com.zimi.model.SysOrgLeader;
import com.zimi.service.SysOrgLeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 机构领导 api
 *
 * @author lxc
 * @since 2019-07-16
 */
@Api
@RestController
@RequestMapping("sys-org-leader")
public class SysOrgLeaderApi {
    @Autowired
    private SysOrgLeaderService sysOrgLeaderService;

    @PostMapping("getLeader")
    @ApiOperation("查询机构和岗位信息")
    public Object getLeader(int orgId) {
        List<SysOrgExtend> list = sysOrgLeaderService.getLeaderPostNameByOrg(orgId);
        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("data", list);
        objectMap.put("code", 0);
        return objectMap;
    }

    @PostMapping("save")
    @ApiOperation("查询机构和岗位信息")
    public Object save(SysOrgLeader leader) {
        sysOrgLeaderService.save(leader);

        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("code", 0);
        return objectMap;
    }

    @PostMapping("moveUp")
    @ApiOperation("查询机构和岗位信息")
    public Object moveUp(SysOrgExtend leader) {
        sysOrgLeaderService.moveUp(leader);

        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("code", 0);
        return objectMap;
    }

    @PostMapping("moveDown")
    @ApiOperation("查询机构和岗位信息")
    public Object save(SysOrgExtend leader) {
        sysOrgLeaderService.moveDown(leader);

        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("code", 0);
        return objectMap;
    }
}
